package com.competition.front.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.competition.front.entity.UserAdditional;
import com.competition.front.mapper.UcenterMemberAdditionalMapper;
import com.competition.front.service.UserAdditionalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-04-01
 */
@Service
public class UserAdditionalServiceImpl extends ServiceImpl<UcenterMemberAdditionalMapper, UserAdditional> implements UserAdditionalService {

    @Override
    public void adduserAdditional(UserAdditional userAdditional) {
        baseMapper.insert(userAdditional);
    }
    @Override
    public void reduceEssayNumber(String userId) {
        QueryWrapper<UserAdditional> userAdditionalQueryWrapper=new QueryWrapper<>();
        userAdditionalQueryWrapper.eq("user_id", userId);
        List<UserAdditional> userAdditionalList = baseMapper.selectList(userAdditionalQueryWrapper);
        Integer essayNumber = userAdditionalList.get(0).getEssayNumber();
        essayNumber=essayNumber-1;
        userAdditionalList.get(0).setEssayNumber(essayNumber);
        UpdateWrapper<UserAdditional> userAdditionalUpdateWrapper=new UpdateWrapper<>();
        userAdditionalUpdateWrapper.eq("user_id",userId);
        baseMapper.update(userAdditionalList.get(0),userAdditionalUpdateWrapper);
    }
}
